home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / keyboard / inpline.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  4.6 KB  |  153 lines

  1. ;void  input_line(col,row,color,max_len,char_case,return_string);
  2. ;  unsigned short  col,row,color,max_len;
  3. ;  char  char_case,*return_string;
  4.  
  5.     EXTRN  _memory_model:byte
  6.     EXTRN  _beep_on:byte
  7.     EXTRN  _error_code:byte
  8.  
  9. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  10.     ASSUME CS:_TEXT
  11.     PUBLIC _input_line
  12. _input_line proc near
  13.     push bp            ;
  14.     mov  bp,sp        ;set up stack frame
  15.     push di            ;
  16.     push si            ;
  17.     mov  _error_code,0    ;assume that no error
  18.     cmp  _memory_model,0    ;near or far?
  19.     jle  begin        ;jump if near
  20.     inc  bp            ;else add 2 to BP
  21.     inc  bp            ;
  22. begin:    cmp  _memory_model,2    ;data near or far?
  23.     jb   L0            ;jump if near
  24.     les  si,dword ptr[bp+14]  ;get ptr to return string
  25.     jmp  short L00        ;
  26. L0:    mov  ax,ds        ;ES = DS
  27.     mov  es,ax        ;
  28.     mov  si,[bp+14]        ;
  29. L00:    mov  byte ptr es:[si],0    ;null string in case an error
  30.     mov  dl,[bp+4]        ;col to DL
  31.     dec  dl            ;count from 0
  32.     cmp  dl,79        ;in range?
  33.     jna  B1            ;jump ahead if so
  34. A1:    inc  _error_code    ;1 = parameter out of range
  35.     jmp  P1            ;else quit
  36. B1:    mov  dh,[bp+6]        ;row to DH
  37.     dec  dh            ;count from 0
  38.     cmp  dh,24        ;in range?
  39.     ja   A1            ;quit if not
  40.     mov  bl,[bp+8]        ;attribute to BL
  41.     sub  bh,bh        ;page 0
  42.     mov  al,[bp+10]        ;max string length to AL
  43.     or   al,al        ;test for zero
  44.     jz   A1            ;quit if zero
  45.     mov  ah,[bp+12]        ;character case to AH
  46.     mov  di,ax        ;store both in DI
  47.     mov  ah,2        ;function to set cursor
  48.     int  10h        ;set the cursor
  49.     mov  bp,si        ;keep BP pointing to descriptor
  50.     sub  al,al        ;initial string length
  51.     mov  es:[si],al        ;set the descriptor
  52. C1:    inc  si            ;forward string pointer
  53. D1:    mov  cx,1        ;num chars to write
  54.     sub  ah,ah        ;func to read keystroke
  55.     int  16h        ;wait for keystroke
  56.     cmp  al,0        ;test for extended code
  57.     je   D1            ;ignore if extended
  58.     cmp  al,13        ;test for carriage return
  59.     jne  E1            ;jump ahead if not CR
  60.     jmp  P1            ;else quit routine
  61. E1:    cmp  al,9        ;test for tab
  62.     je   D1            ;ignore if tab
  63.     cmp  al,27        ;test for Escape
  64.     jne  G1            ;jump ahead if not
  65.     mov  cl,es:[bp]        ;string length to CX
  66.     or   cl,cl        ;test for null string
  67.     je   D1            ;ignore keystroke if null
  68.     mov  es:[bp],ch        ;zero out strg length
  69.     sub  si,si        ;clear string pointer
  70. F1:    dec  dl            ;dec column position
  71.     mov  ah,2        ;function to set cursor
  72.     int  10h        ;reset the cursor
  73.     mov  al,32        ;erase with spc character
  74.     push cx            ;save strg len counter
  75.     mov  cx,1        ;number chars to write
  76.     mov  ah,9        ;function to write char
  77.     int  10h        ;erase a char
  78.     pop  cx            ;restore counter
  79.     loop F1            ;go erase next char
  80.     jmp  short C1        ;go get next keystroke
  81. G1:    cmp  al,8        ;test for backspace
  82.     jne  H1            ;jump ahead if not bkspc
  83.     cmp  es:[bp],ch        ;start of string?
  84.     je   I1            ;go beep, get next key
  85.     sub  es:[bp],cl        ;dec string descriptor
  86.     dec  si            ;dec string pointer
  87.     dec  dl            ;dec cursor col
  88.     mov  ah,2        ;function to set cursor
  89.     int  10h        ;reset cursor
  90.     mov  al,32        ;erase with space char
  91.     mov  ah,9        ;function to write char
  92.     int  10h        ;erase a char
  93.     jmp  short D1        ;get get next char
  94. H1:    xchg di,cx        ;fetch MaxLen
  95.     cmp  es:[bp],cl        ;comp to strg descriptor
  96.     xchg di,cx        ;restore CX
  97.     jne  K1            ;jump if string not full
  98. I1:    push dx            ;save cursor setting
  99.     mov  ah,2        ;DOS func to write char
  100.     mov  dl,7        ;bell character
  101.     cmp  _beep_on,0        ;check whether to beep
  102.     je   J1            ;jump if shouldn't
  103.     int  21h        ;beep!
  104. J1:    pop  dx            ;restore cursor setting
  105.     jmp  short D1        ;go get next keystroke
  106. K1:    xchg cx,di        ;move case type to CH
  107.     cmp  ch,'u'        ;upper case?
  108.     je   L1            ;jump if so
  109.     cmp  ch,'U'        ;upper case?
  110.     jne  M1            ;jump ahead if not
  111. L1:    cmp  al,'a'        ;below 'a'?
  112.     jb   O1            ;move on if out of range
  113.     cmp  al,'z'        ;above 'z'?
  114.     ja   O1            ;move on if out of range
  115.     sub  al,32        ;convert to upper case
  116.     jmp  short O1        ;go write it
  117. M1:    cmp  ch,'l'        ;lower case?
  118.     je   N1            ;jump if so
  119.     cmp  ch,'L'        ;lower case?
  120.     jne  O1            ;no adjustment if not
  121. N1:    cmp  al,'A'        ;below 'A'?
  122.     jb   O1            ;move on if out of range
  123.     cmp  al,'Z'        ;above 'Z'?
  124.     ja   O1            ;move on if out of range
  125.     add  al,32        ;convert to upper case
  126. O1:    xchg cx,di        ;restore CX count
  127.     mov  es:[si],al        ;set keystroke for return
  128.     add  es:[bp],cl        ;increment the descriptor
  129.     mov  ah,9        ;function to write char
  130.     int  10h        ;write the char
  131.     inc  dl            ;forward cursor col
  132.     mov  ah,2        ;function to set cursor
  133.     int  10h        ;reset the cursor
  134.     jmp  C1            ;go get next character
  135. P1:    sub  cx,cx        ;change to C string
  136.     mov  cl,es:[bp]        ;get string length
  137.     jcxz R1            ;quit if null
  138. Q1:    inc  bp            ;
  139.     mov  al,es:[bp]        ;
  140.     mov  es:[bp-1],al    ;
  141.     loop Q1            ;
  142.     mov  byte ptr es:[bp],0    ;null terminator
  143. R1:    pop  si            ;
  144.     pop  di            ;
  145.     pop  bp            ;
  146.     cmp  _memory_model,0    ;quit
  147.     jle  quit        ;
  148.     db   0CBh        ;RET far
  149. quit:    ret            ;RET near
  150. _input_line ENDP
  151. _TEXT    ENDS
  152.     END
  153.